﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZebraCoreLib.Framework;
using System.Data.Linq.Mapping;
using ZebraCoreLib.ZebraException;
using ZebraCoreLib.BasBiz;
using System.Data.Common;
using ZebraCoreLib.Logistics;
using ZebraCoreLib.Stock;

namespace ZebraCoreLib.Order
{

    /// <summary>
    /// 订单明细
    /// </summary>
    [ZebraBizObject(TableName = "osShipExpress")]
    public class OrderDetails : BasBizService<OrderDetails>
    {
        #region OrderDetails 字段属性
        [ZebraField(Title = "编号", DataField = "seID", MaxSize = 32, IsRequired = true, IsAutoID = true)]
        public string ID { get; set; }

        [ZebraField(Title = "客户编号", DataField = "suCode", IsRequired = true)]
        public string SuCode { get; set; }

        [ZebraField(Title = "订单号", DataField = "slCode", IsRequired = true)]
        public string SlCode { get; set; }

        [ZebraField(Title = "物流公司", DataField = "seExpress", IsRequired = true)]
        public string SeExpress { get; set; }

        [ZebraField(Title = "转运单号", DataField = "seCode", IsRequired = true)]
        public string SeCode { get; set; }

        [ZebraField(Title = "", DataField = "seRemark", IsRequired = true)]
        public string SeRemark { get; set; }

        [ZebraField(Title = "", DataField = "seFlag", IsRequired = true)]
        public string SeFlag { get; set; }

        [ZebraField(Title = "", DataField = "seState", IsRequired = true)]
        public string SeState { get; set; }

        [ZebraField(Title = "", DataField = "seSelfID", IsRequired = true)]
        public string SeSelfID { get; set; }

        [ZebraField(Title = "", DataField = "seStoreDate", IsRequired = true)]
        public string SeStoreDate { get; set; }

        [ZebraField(Title = "", DataField = "sgID", IsRequired = true)]
        public string SgID { get; set; }

        [ZebraField(Title = "入库信息", Relationship = "sgid=sgID")]
        public GoodsStock Stock { get; set; }

        [ZebraField(Title = "", DataField = "Qty", IsRequired = true)]
        public string Qty { get; set; }

        [ZebraField(Title = "", DataField = "StoreCode", IsRequired = true)]
        public string StoreCode { get; set; }

        [ZebraField(Title = "", DataField = "GoodsName", IsRequired = true)]
        public string GoodsName { get; set; }

        #endregion


    }

    [ZebraBizObject(TableName = "osshiplist")]
    public class Order : BasBizService<Order>
    {
        #region Order类字段属性
        [ZebraField(Title = "编号", DataField = "siID", IsRequired = true)]
        public string SiID { get; set; }

        [ZebraField(Title = "订单号", DataField = "slcode", IsPrimaryKey = true,IsAutoID = true, IsRequired = true)]
        public string Slcode { get; set; }

        [ZebraField(Title = "仓库", DataField = "slArea", IsRequired = true)]
        public string SlArea { get; set; }

        [ZebraField(Title = "仓库信息", Relationship = "sacode=slArea")]
        public LogisticsCenter LogisticsCenterArea { get; set; }

        [ZebraField(Title = "运单号", DataField = "slAAECode", IsRequired = true)]
        public string SlAAECode { get; set; }

        [ZebraField(Title = "转运单号", DataField = "upsCode", IsRequired = true)]
        public string UpsCode { get; set; }

        [ZebraField(Title = "订单生成时间", DataField = "slDate", IsRequired = true, SortOrder = true, SortByDesc = true)]
        public DateTime SlDate { get; set; }

        [ZebraField(Title = "客户编号", DataField = "suCode", IsRequired = true)]
        public string SuCode { get; set; }

        [ZebraField(Title = "订单状态", DataField = "slFlag", IsRequired = true)]
        public string SlFlag { get; set; }

        [ZebraField(Title = "", DataField = "slPortFlag", IsRequired = true)]
        public string SlPortFlag { get; set; }

        [ZebraField(Title = "", DataField = "slShipRealLbs", IsRequired = true)]
        public string SlShipRealLbs { get; set; }

        [ZebraField(Title = "重量", DataField = "slShipLbs", IsRequired = true)]
        public string SlShipLbs { get; set; }

        [ZebraField(Title = "", DataField = "slShipLWH", IsRequired = true)]
        public string SlShipLWH { get; set; }

        [ZebraField(Title = "", DataField = "slShipLWHl", IsRequired = true)]
        public string SlShipLWHl { get; set; }

        [ZebraField(Title = "", DataField = "slShipLWHw", IsRequired = true)]
        public string SlShipLWHw { get; set; }

        [ZebraField(Title = "", DataField = "slShipLWHh", IsRequired = true)]
        public string SlShipLWHh { get; set; }

        [ZebraField(Title = "", DataField = "slShipLbsX", IsRequired = true)]
        public string SlShipLbsX { get; set; }

        [ZebraField(Title = "", DataField = "slShipType", IsRequired = true)]
        public string SlShipType { get; set; }

        [ZebraField(Title = "", DataField = "slShipTypeX", IsRequired = true)]
        public string SlShipTypeX { get; set; }

        [ZebraField(Title = "", DataField = "slShipPrice", IsRequired = true)]
        public string SlShipPrice { get; set; }

        [ZebraField(Title = "", DataField = "slShipPriceX", IsRequired = true)]
        public string SlShipPriceX { get; set; }

        [ZebraField(Title = "", DataField = "slShipPriceExchange", IsRequired = true)]
        public string SlShipPriceExchange { get; set; }

        [ZebraField(Title = "", DataField = "slShipPriceRmb", IsRequired = true)]
        public string SlShipPriceRmb { get; set; }

        [ZebraField(Title = "", DataField = "slSendRemark", IsRequired = true)]
        public string SlSendRemark { get; set; }

        [ZebraField(Title = "", DataField = "slRecCompany", IsRequired = true)]
        public string SlRecCompany { get; set; }

        [ZebraField(Title = "", DataField = "slRecName", IsRequired = true)]
        public string SlRecName { get; set; }

        [ZebraField(Title = "", DataField = "slRecCountryCode", IsRequired = true)]
        public string SlRecCountryCode { get; set; }

        [ZebraField(Title = "", DataField = "slRecProvinceCode", IsRequired = true)]
        public string SlRecProvinceCode { get; set; }

        [ZebraField(Title = "", DataField = "slRecProvince", IsRequired = true)]
        public string SlRecProvince { get; set; }

        [ZebraField(Title = "", DataField = "slRecCityCode", IsRequired = true)]
        public string SlRecCityCode { get; set; }

        [ZebraField(Title = "", DataField = "slRecCity", IsRequired = true)]
        public string SlRecCity { get; set; }

        [ZebraField(Title = "", DataField = "slRecAddress", IsRequired = true)]
        public string SlRecAddress { get; set; }

        [ZebraField(Title = "", DataField = "slZipCode", IsRequired = true)]
        public string SlZipCode { get; set; }

        [ZebraField(Title = "", DataField = "slRecTel", IsRequired = true)]
        public string SlRecTel { get; set; }

        [ZebraField(Title = "", DataField = "slRecMobi", IsRequired = true)]
        public string SlRecMobi { get; set; }

        [ZebraField(Title = "", DataField = "slProductName", IsRequired = true)]
        public string SlProductName { get; set; }

        [ZebraField(Title = "", DataField = "slProductRemark", IsRequired = true)]
        public string SlProductRemark { get; set; }

        [ZebraField(Title = "", DataField = "slRemark", IsRequired = true)]
        public string SlRemark { get; set; }

        [ZebraField(Title = "", DataField = "slPodPic", IsRequired = true)]
        public string SlPodPic { get; set; }

        [ZebraField(Title = "", DataField = "sIcoFlag", IsRequired = true)]
        public string SIcoFlag { get; set; }

        [ZebraField(Title = "", DataField = "sIcoRemark", IsRequired = true)]
        public string SIcoRemark { get; set; }

        [ZebraField(Title = "", DataField = "sNFlagA", IsRequired = true)]
        public string SNFlagA { get; set; }

        [ZebraField(Title = "", DataField = "sNFlagB", IsRequired = true)]
        public string SNFlagB { get; set; }

        [ZebraField(Title = "", DataField = "slAcDate", IsRequired = true)]
        public string SlAcDate { get; set; }

        [ZebraField(Title = "", DataField = "slAcUser", IsRequired = true)]
        public string SlAcUser { get; set; }

        [ZebraField(Title = "", DataField = "declvalue", IsRequired = true)]
        public double Declvalue { get; set; }

        [ZebraField(Title = "", DataField = "serviceRemark", IsRequired = true)]
        public string ServiceRemark { get; set; }

        [ZebraField(Title = "", DataField = "printFlag", IsRequired = true)]
        public string PrintFlag { get; set; }

        [ZebraField(Title = "", DataField = "printslCode", IsRequired = true)]
        public string PrintslCode { get; set; }

        [ZebraField(Title = "", DataField = "upType", IsRequired = true)]
        public string UpType { get; set; }

        [ZebraField(Title = "", DataField = "slStatus", IsRequired = true)]
        public string SlStatus { get; set; }

        [ZebraField(Title = "", DataField = "shipTitle", IsRequired = true)]
        public string ShipTitle { get; set; }

        [ZebraField(Title = "", DataField = "slTypeID", IsRequired = true)]
        public string SlTypeID { get; set; }

        [ZebraField(Title = "", DataField = "slIsUserPoints", IsRequired = true)]
        public string SlIsUserPoints { get; set; }

        [ZebraField(Title = "", DataField = "serviceID", IsRequired = true)]
        public string ServiceID { get; set; }

        [ZebraField(Title = "", DataField = "slAccFlag", IsRequired = true)]
        public string SlAccFlag { get; set; }

        [ZebraField(Title = "", DataField = "PONO", IsRequired = true)]
        public string PONO { get; set; }

        [ZebraField(Title = "", DataField = "salePlatForm", IsRequired = true)]
        public string SalePlatForm { get; set; }

        [ZebraField(Title = "转运公司简码", DataField = "transCompany", IsRequired = true)]
        public string TransCompany { get; set; }

        [ZebraField(Title = "转运公司", Relationship = "orgID=transCompany")]
        public LogisticsTransCompany LogisticsName { get; set; }

        [ZebraField(Title = "", DataField = "taxPaytype", IsRequired = true)]
        public string TaxPaytype { get; set; }

        [ZebraField(Title = "", DataField = "senderSdID", IsRequired = true)]
        public string SenderSdID { get; set; }

        [ZebraField(Title = "", DataField = "output_flag", IsRequired = true)]
        public string Output_flag { get; set; }

        [ZebraField(Title = "", DataField = "sdId", IsRequired = true)]
        public string SdId { get; set; }

        [ZebraField(Title = "", DataField = "paymentID", IsRequired = true)]
        public string PaymentID { get; set; }

        [ZebraField(Title = "", DataField = "isPayment", IsRequired = true)]
        public string IsPayment { get; set; }

        [ZebraField(Title = "订单明细", Foreignkey = "slcode")]
        public List<OrderDetails> OrderDetails { get; set; }
        #endregion

        public string GetOrderStatus(string flag,string isPayNow)
        {
            string orderStatus = "等待审核";
            switch(flag)
            {
                case "2":
                    orderStatus = "订单已审核";
                    break;
                case "3":
                    orderStatus = "订单已出库";
                    break;
                case "4":
                    orderStatus = "订单已出库";
                    break;
                case "5":
                    orderStatus = "订单已完成";
                    break;
            }
            if (IsPayment == "Y")
                orderStatus += ",订单已付款";
            return orderStatus;
        }
    }
}
